package com.qidianit.mes.pro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.mes.common.Result;
import com.qidianit.mes.pojo.pro.WorkFlow;
import com.qidianit.mes.pro.mapper.WorkFlowMapper;
import com.qidianit.mes.pro.service.WorkFlowService;
import com.qidianit.mes.vo.WorkFlowPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Package Path: com.qidianit.mes.pro.service.impl
 * Author: Alhz
 * Description:
 * Date: 2025/9/17 16:43
 */
@Service
public class WorkFlowServiceImpl implements WorkFlowService {
    @Autowired
    private WorkFlowMapper workFlowMapper;

    /**
     * 分页查询工艺流程
     * @param workFlowPageVo
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public Result selectWorkFlowPage(WorkFlowPageVo workFlowPageVo, int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<WorkFlow> workFlowList = workFlowMapper.selectWorkFlowPage(workFlowPageVo);
        PageInfo<WorkFlow> pageInfo = new PageInfo<>(workFlowList);

        return Result.success(pageInfo);
    }

    /**
     * 根据工艺编号查询单个工艺信息
     * @param code
     * @return
     */
    @Override
    public Result selectWorkFlowByCode(String code) {
        return Result.success(workFlowMapper.selectWorkFlowByCode(code));
    }

    /**
     * 新增工艺流程
     * @param workFlow
     * @return
     */
    @Override
    public Result addWorkFlow(WorkFlow workFlow) {
        return workFlowMapper.addWorkFlow(workFlow)>0?Result.success():Result.error("操作失败");
    }

    /**
     * 编辑工艺流程
     * @param workFlow
     * @return
     */
    @Override
    public Result updateWorkFlow(WorkFlow workFlow) {

        return workFlowMapper.updateWorkFlow(workFlow)>0?Result.success(): Result.error("");
    }

    /**
     * 根据id删除单个工艺
     * @param id
     * @return
     */
    @Override
    public Result deleteWorkFlowById(Long id) {
        return workFlowMapper.deleteWorkFlowById(id)>0?Result.success():Result.error("操作失败");
    }

    /**
     * 批量删除多个工艺
     * @param ids
     * @return
     */
    @Override
    public Result batchDeleteWorkFlow(Long[] ids) {
        return  workFlowMapper.batchDeleteWorkFlow(ids)>0?Result.success():Result.error("操作失败");
    }
}
